<?php
/*回款计划*/
class Payment_record_model extends CI_Model {
	public function __construct() {
		parent :: __construct();
	}

	public function count_nums($name = ''){ /*取得总行数*/
			$user_id = $this->session->userdata('id');
			$role = $this->session->userdata('role');
			$this->db->select('*')->from('payment_record')->join('contract', 'payment_record.contract_id = contract.contract_id')->join('customer', 'payment_record.customer_id = customer.id')->join('user','payment_record.owner_id=user.id');
			if($role == '市场'){
				$this->db->where('payment_record.owner_id',$user_id);
			}
			$count = $this->db->count_all_results();
			return $count;
	}

	public function list_record_plans($limit,$offset = 0){ /*获取分页payment_record数据*/
			$user_id = $this->session->userdata('id');
			$role = $this->session->userdata('role');
			$this->db->select('contract.subject as contract_subject,contract.contract_id as contract_id,customer.customer_name as customer_name,payment_record.*,user.user_name as user_name')->from('payment_record')->join('contract', 'payment_record.contract_id = contract.contract_id')->join('customer', 'payment_record.customer_id = customer.id')->join('user','payment_record.owner_id=user.id');
			if($role == '市场'){
				$this->db->where('payment_record.owner_id',$user_id);
			}
			$this->db->limit($limit,$offset);
			$this->db->order_by('payment_record.create_time', "desc");
			$query = $this->db->get();
			return $query->result();
	}
}
?>
